/**
 * Created on 2007-03-06 23:37
 */
package game.media.gfx;

/**
 * @author David Wallin
 */
public abstract class Entity
{
	private int					m_Xpos;
	private int					m_Ypos;
	private int					m_Width;
	private int					m_Height;
	
	private boolean				m_IsOnDisplay;
	
	protected RenderManager		m_RenderManager = RenderManager.INSTANCE;
	
	/**
	 * Constructor, initializes members
	 * 
	 * @param xpos This entity's x position on the screen (unit is [pixels])
	 * @param ypos This entity's y position on the screen (unit is [pixels])
	 * @param width This entity's width on the screen (unit is [pixels])
	 * @param height This entity's height on the screen (unit is [pixels])
	 */
	public Entity(int xpos, int ypos, int width, int height)
	{
		m_Xpos = xpos;
		m_Ypos = ypos;
		m_Width = width;
		m_Height = height;
		
		m_IsOnDisplay = false;
		
		EntityManager.INSTANCE.addEntity(this);
	}
	
	/**
	 * @return the m_Height
	 */
	public int getHeight()
	{
		return m_Height;
	}
	
	/**
	 * @return the m_Width
	 */
	public int getWidth()
	{
		return m_Width;
	}
	
	/**
	 * @return the m_Xpos
	 */
	public int getXpos()
	{
		return m_Xpos;
	}
	
	/**
	 * @return the m_Ypos
	 */
	public int getYpos()
	{
		return m_Ypos;
	}
	
	/**
	 * @param xpos the m_Xpos to set
	 */
	public void setXpos(int xpos)
	{
		m_Xpos = xpos;
	}
	
	/**
	 * @param ypos the m_Ypos to set
	 */
	public void setYpos(int ypos)
	{
		m_Ypos = ypos;
	}
	
	/**
	 * Displays or hides this entity
	 */
	public void display(boolean display)
	{
		m_IsOnDisplay = display;
	}
	
	/**
	 * Gets the display state of this entity
	 * 
	 * @return true if this entity is on display, otherwise false
	 */
	public boolean isOnDisplay()
	{
		return m_IsOnDisplay;
	}
	
	/**
	 * Call this method to draw the entity to the screen.
	 * The entity will only be drawn if a call to display has first
	 * been made, with the argument 'true'
	 */
	public final void draw()
	{
		if(m_IsOnDisplay)
		{
			doDraw();
		}
	}
	
	/**
	 * Implement this method to draw the entity to the screen
	 */
	protected abstract void doDraw();
}
